﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using DataAccess;
using DTO;
namespace Business
{
    public class AccountBUS
    {


        public static string MD5(string src)
        {
            StringBuilder builder = new StringBuilder(32);

            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] srcData = Encoding.UTF8.GetBytes(src);
            byte[] encryptedData = md5.ComputeHash(srcData);

            foreach (byte data in encryptedData)
            {
                if (data < 16)
                    builder.Append("0");
                builder.Append(data.ToString("x"));
            }
            return builder.ToString().ToUpper();
        }

        public static List<AccountDTO> GetAccountList()
        {
            return AccountDAO.GetAccountList();
        }

        public static bool IsAccountExists(AccountDTO dtoAccount)
        {
            return AccountDAO.FindAccountByUserName(dtoAccount) != null;
        }

        public static AccountDTO FindAccountByUserName(AccountDTO dtoAccount)
        {
            return AccountDAO.FindAccountByUserName(dtoAccount);
        }

        public static bool AddNewAccount(AccountDTO dtoAccount)
        {
            return AccountDAO.AddNewAccount(dtoAccount);
        }

        public static bool UpdateAccount(AccountDTO dtoAccount)
        {
            return AccountDAO.UpdateAccount(dtoAccount);
        }

        public static bool DeleteAAccount(AccountDTO dtoAccount)
        {
            return AccountDAO.DeleteAAccount(dtoAccount);
        }

        public static bool DeleteAllAccount()
        {
            return AccountDAO.DeleteAllAccount();
        }
    }
}
